import { ref, nextTick, onMounted } from 'vue';

export function useOverflow(lineHeight = 22, maxRows = 3) {
    const target = ref<HTMLElement>(); // 用 template ref 绑定
    const isOverflow = ref(false);

    const judge = async () => {
        await nextTick(); // 确保 DOM 已更新
        if (!target.value) return;
        const maxH = lineHeight * maxRows;
        isOverflow.value = target.value.scrollHeight > maxH;
    };

    onMounted(judge); // 组件挂载后判断一次
    return { target, isOverflow, judge }; // judge 可手动再次调用
}
